package cn.chenfeifx.example.examples;

import cn.chenfeifx.core.common.FxUtil;
import cn.chenfeifx.core.common.SimpleButton;
import cn.chenfeifx.core.controls.CFPopover;
import cn.chenfeifx.core.enums.Level;
import javafx.scene.image.ImageView;
import javafx.scene.layout.HBox;
import javafx.scene.layout.StackPane;

import java.util.concurrent.atomic.AtomicInteger;

//气泡卡片 案例
public class CFPopoverExample extends StackPane {

    SimpleButton simpleButton = new SimpleButton("点我试试");
    SimpleButton nextButton = SimpleButton.get(CFPopover.Pos.BOTTOM_LEFT.name().replace("_", "-"), Level.SUCCESS);
    //
    HBox hBox = new HBox(nextButton, simpleButton);
    //
    StackPane content = new StackPane(new ImageView(FxUtil.getImage("/img/logo.png")));
    CFPopover popover = new CFPopover(simpleButton, content);

    public CFPopoverExample() {
        getChildren().addAll(hBox);
        //
        hBox.setMaxSize(USE_PREF_SIZE, USE_PREF_SIZE);
        hBox.setSpacing(20);
        content.setPrefSize(200, 200);

        AtomicInteger i = new AtomicInteger(0);
        CFPopover.Pos[] positionArr = {
                CFPopover.Pos.BOTTOM_LEFT, CFPopover.Pos.BOTTOM_CENTER, CFPopover.Pos.BOTTOM_RIGHT,
                CFPopover.Pos.TOP_LEFT, CFPopover.Pos.TOP_CENTER, CFPopover.Pos.TOP_RIGHT,
                CFPopover.Pos.RIGHT_TOP, CFPopover.Pos.RIGHT_CENTER, CFPopover.Pos.RIGHT_BOTTOM,
                CFPopover.Pos.LEFT_TOP, CFPopover.Pos.LEFT_CENTER, CFPopover.Pos.LEFT_BOTTOM
        };
        //
        simpleButton.setOnMouseClicked(event -> {
            popover.setPos(positionArr[i.get()]);// 设置显示的位置
            popover.show();
        });
        //切换显示的位置
        nextButton.setOnMouseClicked(event -> {
            i.getAndIncrement();
            if (i.get() >= positionArr.length) {
                i.set(0);
            }
            nextButton.setText(positionArr[i.get()].name().replace("_", "-"));
        });
    }
}
